//
// Created by Jisam on 29/09/2024 7:56 PM.
// Solution of  小红的中位数查询（easy）
#include <bits/stdc++.h>

#define  int long long
using namespace std;


signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    vector<int> a(n);
    for(int i = 0 ; i < n; i ++) cin >> a[i];
    sort(a.begin(),a.end());
    while(q --){
        int l ,r;
        cin >> l >> r;
        l--; r--; // 转换为0-based索引
        vector<int> sub(a.begin() + l, a.begin() + r + 1);
        sort(sub.begin(), sub.end());
        cout << sub[(r - l + 1) / 2] << endl;
    }


    return 0;
}